home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / include / arpa / nameser.h < prev    next >
C/C++ Source or Header  |  1988-10-23  |  6KB  |  213 lines

  1. /*
  2.  * Copyright (c) 1983 Regents of the University of California.
  3.  * All rights reserved.  The Berkeley software License Agreement
  4.  * specifies the terms and conditions for redistribution.
  5.  *
  6.  *    @(#)nameser.h    5.17 (Berkeley) 11/17/87
  7.  */
  8.  
  9. #ifndef _NAMESER
  10. #define _NAMESER
  11.  
  12. #include <machparam.h>
  13.  
  14. /*
  15.  * Define constants based on rfc883
  16.  */
  17. #define PACKETSZ    512        /* maximum packet size */
  18. #define MAXDNAME    256        /* maximum domain name */
  19. #define MAXCDNAME    255        /* maximum compressed domain name */
  20. #define MAXLABEL    63        /* maximum length of domain label */
  21.     /* Number of bytes of fixed size data in query structure */
  22. #define QFIXEDSZ    4
  23.     /* number of bytes of fixed size data in resource record */
  24. #define RRFIXEDSZ    10
  25.  
  26. /*
  27.  * Internet nameserver port number
  28.  */
  29. #define NAMESERVER_PORT    53
  30.  
  31. /*
  32.  * Currently defined opcodes
  33.  */
  34. #define QUERY        0x0        /* standard query */
  35. #define IQUERY        0x1        /* inverse query */
  36. #define STATUS        0x2        /* nameserver status query */
  37. /*#define xxx        0x3        /* 0x3 reserved */
  38.     /* non standard */
  39. #define UPDATEA        0x9        /* add resource record */
  40. #define UPDATED        0xa        /* delete a specific resource record */
  41. #define UPDATEDA    0xb        /* delete all nemed resource record */
  42. #define UPDATEM        0xc        /* modify a specific resource record */
  43. #define UPDATEMA    0xd        /* modify all named resource record */
  44.  
  45. #define ZONEINIT    0xe        /* initial zone transfer */
  46. #define ZONEREF        0xf        /* incremental zone referesh */
  47.  
  48. /*
  49.  * Currently defined response codes
  50.  */
  51. #define NOERROR        0        /* no error */
  52. #define FORMERR        1        /* format error */
  53. #define SERVFAIL    2        /* server failure */
  54. #define NXDOMAIN    3        /* non existent domain */
  55. #define NOTIMP        4        /* not implemented */
  56. #define REFUSED        5        /* query refused */
  57.     /* non standard */
  58. #define NOCHANGE    0xf        /* update failed to change db */
  59.  
  60. /*
  61.  * Type values for resources and queries
  62.  */
  63. #define T_A        1        /* host address */
  64. #define T_NS        2        /* authoritative server */
  65. #define T_MD        3        /* mail destination */
  66. #define T_MF        4        /* mail forwarder */
  67. #define T_CNAME        5        /* connonical name */
  68. #define T_SOA        6        /* start of authority zone */
  69. #define T_MB        7        /* mailbox domain name */
  70. #define T_MG        8        /* mail group member */
  71. #define T_MR        9        /* mail rename name */
  72. #define T_NULL        10        /* null resource record */
  73. #define T_WKS        11        /* well known service */
  74. #define T_PTR        12        /* domain name pointer */
  75. #define T_HINFO        13        /* host information */
  76. #define T_MINFO        14        /* mailbox information */
  77. #define T_MX        15        /* mail routing information */
  78.     /* non standard */
  79. #define T_UINFO        100        /* user (finger) information */
  80. #define T_UID        101        /* user ID */
  81. #define T_GID        102        /* group ID */
  82. #define T_UNSPEC    103        /* Unspecified format (binary data) */
  83.     /* Query type values which do not appear in resource records */
  84. #define T_AXFR        252        /* transfer zone of authority */
  85. #define T_MAILB        253        /* transfer mailbox records */
  86. #define T_MAILA        254        /* transfer mail agent records */
  87. #define T_ANY        255        /* wildcard match */
  88.  
  89. /*
  90.  * Values for class field
  91.  */
  92.  
  93. #define C_IN        1        /* the arpa internet */
  94. #define C_CHAOS        3        /* for chaos net at MIT */
  95.     /* Query class values which do not appear in resource records */
  96. #define C_ANY        255        /* wildcard match */
  97.  
  98. /*
  99.  * Status return codes for T_UNSPEC conversion routines
  100.  */
  101. #define CONV_SUCCESS 0
  102. #define CONV_OVERFLOW -1
  103. #define CONV_BADFMT -2
  104. #define CONV_BADCKSUM -3
  105. #define CONV_BADBUFLEN -4
  106.  
  107. /*
  108.  * Structure for query header, the order of the fields is machine and
  109.  * compiler dependent, in our case, the bits within a byte are assignd
  110.  * least significant first, while the order of transmition is most
  111.  * significant first.  This requires a somewhat confusing rearrangement.
  112.  */
  113.  
  114. typedef struct {
  115.     u_short    id;        /* query identification number */
  116. #if defined (sun) || defined (sel) || defined (pyr) || defined (is68k) \
  117. || defined (tahoe) || defined (BIT_ZERO_ON_LEFT) || (BYTE_ORDER == BIG_ENDIAN)
  118.     /* Bit zero on left:  Gould and similar architectures */
  119.             /* fields in third byte */
  120.     u_char    qr:1;        /* response flag */
  121.     u_char    opcode:4;    /* purpose of message */
  122.     u_char    aa:1;        /* authoritive answer */
  123.     u_char    tc:1;        /* truncated message */
  124.     u_char    rd:1;        /* recursion desired */
  125.             /* fields in fourth byte */
  126.     u_char    ra:1;        /* recursion available */
  127.     u_char    pr:1;        /* primary server required (non standard) */
  128.     u_char    unused:2;    /* unused bits */
  129.     u_char    rcode:4;    /* response code */
  130. #else
  131. #if defined (vax) || defined(ns32000) || defined (BIT_ZERO_ON_RIGHT) \
  132. || (BYTE_ORDER == LITTLE_ENDIAN)
  133.     /* Bit zero on right:  VAX */
  134.             /* fields in third byte */
  135.     u_char    rd:1;        /* recursion desired */
  136.     u_char    tc:1;        /* truncated message */
  137.     u_char    aa:1;        /* authoritive answer */
  138.     u_char    opcode:4;    /* purpose of message */
  139.     u_char    qr:1;        /* response flag */
  140.             /* fields in fourth byte */
  141.     u_char    rcode:4;    /* response code */
  142.     u_char    unused:2;    /* unused bits */
  143.     u_char    pr:1;        /* primary server required (non standard) */
  144.     u_char    ra:1;        /* recursion available */
  145. #else
  146.     /* you must determine what the correct bit order is for your compiler */
  147.     UNDEFINED_BIT_ORDER;
  148. #endif
  149. #endif
  150.             /* remaining bytes */
  151.     u_short    qdcount;    /* number of question entries */
  152.     u_short    ancount;    /* number of answer entries */
  153.     u_short    nscount;    /* number of authority entries */
  154.     u_short    arcount;    /* number of resource entries */
  155. } HEADER;
  156.  
  157. /*
  158.  * Defines for handling compressed domain names
  159.  */
  160. #define INDIR_MASK    0xc0
  161.  
  162. /*
  163.  * Structure for passing resource records around.
  164.  */
  165. struct rrec {
  166.     short    r_zone;            /* zone number */
  167.     short    r_class;        /* class number */
  168.     short    r_type;            /* type number */
  169.     u_long    r_ttl;            /* time to live */
  170.     int    r_size;            /* size of data area */
  171.     char    *r_data;        /* pointer to data */
  172. };
  173.  
  174. extern    u_short    _getshort();
  175. extern    u_long    _getlong();
  176.  
  177. /*
  178.  * Inline versions of get/put short/long.
  179.  * Pointer is advanced; we assume that both arguments
  180.  * are lvalues and will already be in registers.
  181.  * cp MUST be u_char *.
  182.  */
  183. #define GETSHORT(s, cp) { \
  184.     (s) = *(cp)++ << 8; \
  185.     (s) |= *(cp)++; \
  186. }
  187.  
  188. #define GETLONG(l, cp) { \
  189.     (l) = *(cp)++ << 8; \
  190.     (l) |= *(cp)++; (l) <<= 8; \
  191.     (l) |= *(cp)++; (l) <<= 8; \
  192.     (l) |= *(cp)++; \
  193. }
  194.  
  195.  
  196. #define PUTSHORT(s, cp) { \
  197.     *(cp)++ = (s) >> 8; \
  198.     *(cp)++ = (s); \
  199. }
  200.  
  201. /*
  202.  * Warning: PUTLONG destroys its first argument.
  203.  */
  204. #define PUTLONG(l, cp) { \
  205.     (cp)[3] = l; \
  206.     (cp)[2] = (l >>= 8); \
  207.     (cp)[1] = (l >>= 8); \
  208.     (cp)[0] = l >> 8; \
  209.     (cp) += sizeof(u_long); \
  210. }
  211.  
  212. #endif /* _NAMESER */
  213.